import React, {useEffect, useState} from 'react';
import {Button, Descriptions, List, message, Space} from "antd";
import useBindWx from "@/pages/notify/useBindWx";
import jsCookie from "js-cookie";
import {RedoOutlined} from "@ant-design/icons"


function Notify(props) {
    const [openid,setOpenid] = useState()
    const items = [
        {
            key: '1',
            label: '绑定微信',
            children: <Space>
                {!openid?'未绑定':"已绑定"}
                <RedoOutlined style={{
                    fontSize:20,
                    color:"#5555ff",
                    cursor:"pointer",
                }}
                    onClick={queryList}
                />
            </Space>,
        },
        // {
        //     key: '2',
        //     label: 'Telephone',
        //     children: '1810000000',
        // },
        // {
        //     key: '3',
        //     label: 'Live',
        //     children: 'Hangzhou, Zhejiang',
        // },
    ]
    function queryList(){
        const info = JSON.parse(jsCookie.get("info") || "{}")
        ax.get("/gzh/userInfo",{
            params:{
                ID:info.id
            }
        }).then(res=>{
            const {wxId} = res.data;
            if (wxId){
                message.success("已绑定")
            }else{
                message.warning("未绑定微信")
            }
            if(wxId){
                setOpenid(wxId)
            }
        })
    }
    useEffect(()=>{
        queryList()
    },[])
    const {setOpen,ModalDOM} = useBindWx({
        queryList
    })
    return (
        <div>
            <Descriptions title="通知设置" items={items} />
            {!openid && <Button type={"primary"} onClick={()=>setOpen(true)}>绑定微信消息</Button>}
            {ModalDOM}
        </div>
    );
}

export default Notify;